define(function(require, exports, module) {

	require("bootstrap"), require("bootstrapPaginator");

	exports.init = function() {

		$('#paginator').bootstrapPaginator({
			size: "small",
			bootstrapMajorVersion: 3,
			currentPage: $("#hidPage").val(),
			numberOfPages: 10,
			totalPages: $("#hidTotalCount").val(),
			pageUrl: function(type, page, current) {
				return "/admin/news/" + page;
			}
		});
		$("#del").bind("click", del);
		$("#chb_all").bind("change", choose);
	};


	function del() {

		if ($("input[flag]:checked").length == 0) return;

		var _ids = "";
		$("input[flag]:checked").each(function() {
			_ids += $(this).attr("flag") + ";";
		});
		$.ajax({
			type: 'post',
			url: '/admin/news/dels',
			data: {
				ids: _ids
			},
			success: function(data) {
				if (data.result)
					location.href = "/admin/news/1";
			}
		});
	}

	function choose() {

		var isChecked = $(this)[0].checked;
		$("input[flag]").each(function() {
			$(this)[0].checked = isChecked;
		});
	}
});